﻿var lsInfo = {
  current: 1,
  pageSize: allPageSize,
  data: [],
  totalRow: 0,
  totalPage: 0,
  oneDate: {},
  editState: false
};

$('#nav li').eq(0).addClass('active');

var now = new Date();
var nowDay = now.getDate() + 1;
var nowMonth = now.getMonth();
var nowYear = now.getFullYear();
var nowDayOfWeek = now.getDay();

var getWeekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek);
var getWeekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek));

$('#week').html(getWeekStartDate.pattern('yyyy年MM月dd日') + ' - ' + getWeekEndDate.pattern('yyyy年MM月dd日'));

var getList = function (obj) {
  $.ajax({
    cache: false,
    async: false,
    url: '/api/CommonApi?API=GetProjects',
    type: 'get',
    data: {
      ProjectName: searchObj.ProjectName,
      StartDate: searchObj.StartDate,
      EndDate: searchObj.EndDate,
      sorts: ' StartDate DESC',
      pagesize: obj.size,
      page: obj.index
    },
    dataType: 'json',
    success: function (data) {
      if (data.Success) {
        obj.callback(data)
      }
    }
  });
};

/*getList({
 size: lsInfo.pageSize,
 index: lsInfo.current,
 callback: function (data) {
 // console.log(data)
 // console.log(JSON.stringify(data));
 var newData = data.ApiParamObj[0];
 for (var key in newData) {
 // console.log(newData[key])
 newData[key].StartDate = new Date(newData[key].StartDate).pattern('yyyy/MM/dd');
 newData[key].EndDate = new Date(newData[key].EndDate).pattern('yyyy/MM/dd');
 if (newData[key]['State'] === '????') {
 newData[key]['State'] = '';
 }
 }
 // 列表数据
 document.getElementById('listTable').innerHTML = template('l2List', newData);
 // 分页
 var pagesInfo = data.ApiParamObj[1];
 lsInfo.data = newData;
 lsInfo.totalRow = pagesInfo[0].totalRow;
 lsInfo.totalPage = pagesInfo[0].totalPage;

 $('#totalRow').html(lsInfo.totalRow);
 pagesSet(lsInfo);
 setPageSize(lsInfo);
 loading.hide();
 }
 });*/

// 点击分页请求事件
var showPage = function (o) {
  // console.log(o)
  getList({
    size: o.pageSize,
    index: o.current,
    callback: function (data) {
      // console.log(data)
      // console.log(JSON.stringify(data));
      var newData = data.ApiParamObj[0];
      for (var key in newData) {
        newData[key].StartDate = new Date(newData[key].StartDate).pattern('yyyy/MM/dd');
        newData[key].EndDate = new Date(newData[key].EndDate).pattern('yyyy/MM/dd');
        if (newData[key]['State'] === '????') {
          newData[key]['State'] = '';
        }
      }
      // 列表数据
      document.getElementById('listTable').innerHTML = template('l2List', newData);
      // 分页
      var pagesInfo = data.ApiParamObj[1];
      o.data = newData;
      o.totalRow = pagesInfo[0].totalRow;
      o.totalPage = pagesInfo[0].totalPage;

      $('#totalRow').html(o.totalRow);
      pagesSet(o);
      loading.hide();
    }
  });
};


$('#thisWeek').click(function () {

});